/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package pies.chat.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import pies.chat.model.Device;
import pies.chat.model.DeviceModel;

import java.io.Serializable;

import java.sql.Types;

import java.util.HashMap;
import java.util.Map;

/**
 * The base model implementation for the Device service. Represents a row in the &quot;PIES_Device&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link pies.chat.model.DeviceModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link DeviceImpl}.
 * </p>
 *
 * @author HoangAnh
 * @see DeviceImpl
 * @see pies.chat.model.Device
 * @see pies.chat.model.DeviceModel
 * @generated
 */
public class DeviceModelImpl extends BaseModelImpl<Device>
	implements DeviceModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a device model instance should use the {@link pies.chat.model.Device} interface instead.
	 */
	public static final String TABLE_NAME = "PIES_Device";
	public static final Object[][] TABLE_COLUMNS = {
			{ "deviceId", Types.BIGINT },
			{ "deviceToken", Types.VARCHAR },
			{ "deviceName", Types.VARCHAR }
		};
	public static final String TABLE_SQL_CREATE = "create table PIES_Device (deviceId LONG not null primary key,deviceToken VARCHAR(75) null,deviceName VARCHAR(75) null)";
	public static final String TABLE_SQL_DROP = "drop table PIES_Device";
	public static final String ORDER_BY_JPQL = " ORDER BY device.deviceId ASC";
	public static final String ORDER_BY_SQL = " ORDER BY PIES_Device.deviceId ASC";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.pies.chat.model.Device"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.pies.chat.model.Device"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = false;
	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.pies.chat.model.Device"));

	public DeviceModelImpl() {
	}

	@Override
	public long getPrimaryKey() {
		return _deviceId;
	}

	@Override
	public void setPrimaryKey(long primaryKey) {
		setDeviceId(primaryKey);
	}

	@Override
	public Serializable getPrimaryKeyObj() {
		return _deviceId;
	}

	@Override
	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	@Override
	public Class<?> getModelClass() {
		return Device.class;
	}

	@Override
	public String getModelClassName() {
		return Device.class.getName();
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("deviceId", getDeviceId());
		attributes.put("deviceToken", getDeviceToken());
		attributes.put("deviceName", getDeviceName());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long deviceId = (Long)attributes.get("deviceId");

		if (deviceId != null) {
			setDeviceId(deviceId);
		}

		String deviceToken = (String)attributes.get("deviceToken");

		if (deviceToken != null) {
			setDeviceToken(deviceToken);
		}

		String deviceName = (String)attributes.get("deviceName");

		if (deviceName != null) {
			setDeviceName(deviceName);
		}
	}

	@Override
	public long getDeviceId() {
		return _deviceId;
	}

	@Override
	public void setDeviceId(long deviceId) {
		_deviceId = deviceId;
	}

	@Override
	public String getDeviceToken() {
		if (_deviceToken == null) {
			return StringPool.BLANK;
		}
		else {
			return _deviceToken;
		}
	}

	@Override
	public void setDeviceToken(String deviceToken) {
		_deviceToken = deviceToken;
	}

	@Override
	public String getDeviceName() {
		if (_deviceName == null) {
			return StringPool.BLANK;
		}
		else {
			return _deviceName;
		}
	}

	@Override
	public void setDeviceName(String deviceName) {
		_deviceName = deviceName;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
			Device.class.getName(), getPrimaryKey());
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		ExpandoBridge expandoBridge = getExpandoBridge();

		expandoBridge.setAttributes(serviceContext);
	}

	@Override
	public Device toEscapedModel() {
		if (_escapedModel == null) {
			_escapedModel = (Device)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelInterfaces, new AutoEscapeBeanHandler(this));
		}

		return _escapedModel;
	}

	@Override
	public Object clone() {
		DeviceImpl deviceImpl = new DeviceImpl();

		deviceImpl.setDeviceId(getDeviceId());
		deviceImpl.setDeviceToken(getDeviceToken());
		deviceImpl.setDeviceName(getDeviceName());

		deviceImpl.resetOriginalValues();

		return deviceImpl;
	}

	@Override
	public int compareTo(Device device) {
		long primaryKey = device.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}

		if (!(obj instanceof Device)) {
			return false;
		}

		Device device = (Device)obj;

		long primaryKey = device.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
	}

	@Override
	public CacheModel<Device> toCacheModel() {
		DeviceCacheModel deviceCacheModel = new DeviceCacheModel();

		deviceCacheModel.deviceId = getDeviceId();

		deviceCacheModel.deviceToken = getDeviceToken();

		String deviceToken = deviceCacheModel.deviceToken;

		if ((deviceToken != null) && (deviceToken.length() == 0)) {
			deviceCacheModel.deviceToken = null;
		}

		deviceCacheModel.deviceName = getDeviceName();

		String deviceName = deviceCacheModel.deviceName;

		if ((deviceName != null) && (deviceName.length() == 0)) {
			deviceCacheModel.deviceName = null;
		}

		return deviceCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(7);

		sb.append("{deviceId=");
		sb.append(getDeviceId());
		sb.append(", deviceToken=");
		sb.append(getDeviceToken());
		sb.append(", deviceName=");
		sb.append(getDeviceName());
		sb.append("}");

		return sb.toString();
	}

	@Override
	public String toXmlString() {
		StringBundler sb = new StringBundler(13);

		sb.append("<model><model-name>");
		sb.append("pies.chat.model.Device");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>deviceId</column-name><column-value><![CDATA[");
		sb.append(getDeviceId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>deviceToken</column-name><column-value><![CDATA[");
		sb.append(getDeviceToken());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>deviceName</column-name><column-value><![CDATA[");
		sb.append(getDeviceName());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = Device.class.getClassLoader();
	private static Class<?>[] _escapedModelInterfaces = new Class[] { Device.class };
	private long _deviceId;
	private String _deviceToken;
	private String _deviceName;
	private Device _escapedModel;
}